package cs575.wido.ui;

import cs575.client.GroupEx;
import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

import cs575.wido.User;
import cs575.wido.action.InviteMemberAction;
import cs575.wido.action.RemoveGroupMemberAction;
import cs575.wido.action.UserAccountAction;
import cs575.wido.model.MemberListModel;

public class GroupMemberViewer extends JPanel {
	private JList memberList;
	private MemberListModel memberListModel;
	
	private GroupEx group;

	public GroupMemberViewer() {
		this.setLayout(new BorderLayout(0, 0));
		
		memberListModel = new MemberListModel();
		memberList = new JList(memberListModel);
		JScrollPane scrollPane = new JScrollPane(memberList);
		this.add(scrollPane);
		this.add(buildButtonPane(), BorderLayout.SOUTH);		
	}
	
	private JComponent buildButtonPane() {
		JPanel buttonPane = new JPanel();
		FlowLayout flowLayout = (FlowLayout) buttonPane.getLayout();
		flowLayout.setAlignment(FlowLayout.RIGHT);
		
		JButton btnInvite = new JButton("Invite New Member");
		buttonPane.add(btnInvite);
		
		JButton btnAccount = new JButton("User Account");
		buttonPane.add(btnAccount);
		
		JButton btnSetRole = new JButton("Set Role");
		buttonPane.add(btnSetRole);
		
		JButton btnRemove = new JButton("Remove");
		buttonPane.add(btnRemove);
		
		// set actions
		btnInvite.setAction(new InviteMemberAction(this));
		User user = new User();
		btnAccount.setAction(new UserAccountAction(user));
		btnRemove.setAction(new RemoveGroupMemberAction(this));
		
		return buttonPane;
	}

	public JList getMemberList() {
		return memberList;
	}

	public MemberListModel getMemberListModel() {
		return memberListModel;
	}

	public GroupEx getGroup() {
		return group;
	}

	public void setGroup(GroupEx group) {
		this.group = group;
		this.memberListModel.setGroup(group);
	}
	
	
}
